import dsktConstant from '../../config/constant.js'
const  cookie = {
	key:{
		schoolNo:'schoolNo',
		userId:'userId',
		schoolId:'schoolId',
		schoolName:'schoolName',
		departmentName:'departmentName',
		majorName:'majorName',
		titleName:'titleName',
		userNo:'userNo',
		userName:'userName',
		userFileId:'userFileId',
		operCellphone:'oper_cellphone',
		headImg:'headImg',
		token:'token',
		openId:'openId',
		wxAppId:'wxAppId',
		LoginUserType: 'LoginUserType',
		openOrderStuFileId: "openOrderStuFileId",
		openOrderStuUserId: "openOrderStuUserId",
		openOrderStuName: "openOrderStuName",
		openOrderStuCellphone: "openOrderStuCellphone",
		isWechatOpenOrder: "isWechatOpenOrder",
		NOWTYPE: "NOWTYPE",
		StaffNo: "StaffNo",
	},
	
	setOpenInfoToData(data){
		data.operUserId = cookie.get(cookie.key.userId);
		data.operFileId = cookie.get(cookie.key.userFileId);
		data.operName = cookie.get(cookie.key.userName);
		data.schoolId = cookie.get(cookie.key.schoolId);
		data.userNo = cookie.get(cookie.key.userNo);
		data.operPlatform = 1; //操作平台
		data.operCellphone = cookie.get(cookie.key.operCellphone);
		return data;
	},
	setLoginUserData(data){
		cookie.set(cookie.key.userName,data.name);
		cookie.set(cookie.key.userFileId,data.id);
		cookie.set(cookie.key.userNo , data.no);
		cookie.set(cookie.key.operCellphone,data.cellphone);
		if (data.schoolName){
			cookie.set(cookie.key.schoolName,data.schoolName);
		}
		if (data.isWechatOpenOrder==1) {
			cookie.set(cookie.key.isWechatOpenOrder, true);
		} else {
		 	cookie.set(cookie.key.isWechatOpenOrder, false);
		}
		cookie.set(cookie.key.departmentName,data.departmentName);
		cookie.set(cookie.key.majorName,data.majorName);
		cookie.set(cookie.key.titleName,data.titleName);
		cookie.set(cookie.key.headImg,data.headImg);
		if(data.suitImg)
		cookie.set(cookie.key.headImg,data.suitImg);
	},
	getLoginUserData(){
		var data={};
		data.schoolNo = cookie.get(cookie.key.schoolNo);
		data.userId = cookie.get(cookie.key.userId);
		data.schoolId = cookie.get(cookie.key.schoolId);
		data.schoolName = cookie.get(cookie.key.schoolName);
		data.departmentName = cookie.get(cookie.key.departmentName);
		data.majorName = cookie.get(cookie.key.majorName);
		data.titleName = cookie.get(cookie.key.titleName);
		data.userNo = cookie.get(cookie.key.userNo);
		data.userName = cookie.get(cookie.key.userName);
		data.userFileId = cookie.get(cookie.key.userFileId);
		data.operCellphone = cookie.get(cookie.key.operCellphone);
		data.headImg = cookie.get(cookie.key.headImg);
		return data;
	},
	getUserId(){
		return cookie.get(cookie.key.userId);
	},
	getAppid(){
		if(dsktConstant.debug){
		//	return 'wx5d9cbe3fe27820cb';
			return 'wx46f0250b0ad9a5a4';
		}else{
			return cookie.get(cookie.key.wxAppId);
		}
	},
	setUserData(data){
		data.operUserId = cookie.get(cookie.key.userId);
		data.operFileId = cookie.get(cookie.key.userFileId);
		return data;
	},
	set: function (name, value) {
		return localStorage.setItem(name,value);
	},
	get: function (name) {
		return localStorage.getItem(name);
	},
	delete: function (name) {
		return localStorage.removeItem(name);
	},
	clear: function () {
		return localStorage.clear();
	}
	
}

export default cookie;